package com.ruanyuan.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruanyuan.pojo.MessInfo;
import com.ruanyuan.pojo.Reply;
import com.ruanyuan.service.ReplyService;
import com.ruanyuan.utils.Page;

/**
 * 留言回复控制器
 * 
 * @author zbp
 *
 */
@Controller
@RequestMapping("/Reply")
public class ReplyController {
	// 注入回复业务层
	@Autowired
	private ReplyService replyService;

	// 添加回复信息
	@RequestMapping("/addReply")
	@ResponseBody
	public String addReply(String replyInfo, Integer messId, HttpSession session) {
		// 获取session内容
		String userName = (String) session.getAttribute("userName");
		// 创建DateFormat对象
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		// 获取系统当前时间
		String nowTime = dateFormat.format(new Date());
		// 实例化留言实体类
		MessInfo messInfo = new MessInfo();
		messInfo.setMessId(messId);
		// 实例化回复实体类
		Reply reply = new Reply();
		reply.setReplyAuthor(userName);
		reply.setMessInfo(messInfo);
		reply.setReplyInfo(replyInfo);
		reply.setReplyTime(nowTime);
		// 调用添加回复方法
		int rows = replyService.addReply(reply);
		if (rows > 0) {
			System.out.println("添加成功");
			return "OK";
		} else {
			return "false";
		}
	}
}
